Skip to content

Fix KeyNotFoundException / ArgumentException on drawing rename and removal#2379

Merged
swmal merged 1 commit into
EPPlusSoftware:develop8from
lievendf:fix/drawing-rename-removal-failure
Jun 18, 2026
Merged

Fix KeyNotFoundException / ArgumentException on drawing rename and removal#2379
swmal merged 1 commit into
EPPlusSoftware:develop8from
lievendf:fix/drawing-rename-removal-failure

Conversation

@lievendf

@lievendf lievendf commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Problem

  1. Drawing Renaming: Renaming an ExcelDrawing updated the underlying XML but failed to synchronize the change with the parent's _drawingNames lookup dictionary. This caused subsequent lookups and Remove() calls on renamed drawings to fail with a KeyNotFoundException.
  2. Group Shape Removal: ExcelDrawingsGroup.Remove() removed drawings from the internal list but did not clean up their entries from the _drawingNames dictionary or re-index the remaining shapes, causing index desynchronization.
  3. Case Sensitivity: The _drawingNames dictionary in ExcelDrawingsGroup was case-sensitive, unlike the worksheet-level dictionary which is case-insensitive, resulting in inconsistent behavior.

Solution

  • Synchronized Renaming: Updated the ExcelDrawing.Name setter to validate uniqueness across both worksheet and group-level collections first, then update both lookup dictionaries.
  • Group Shape Re-indexing: Fixed ExcelDrawingsGroup.Remove to remove the shape's name from _drawingNames and re-index the shifted indices of the remaining drawings in the group.
  • Case-Insensitive Group Lookup: Initialized _drawingNames in ExcelDrawingsGroup with StringComparer.OrdinalIgnoreCase to align with worksheet-level drawing lookups.

Testing

Added unit tests in DrawingTest.cs to verify renaming and removal behavior for both standard and grouped drawings:

  • DrawingNameChangeAndRemovalTest
  • GroupedDrawingNameChangeAndRemovalTest

@swmal

swmal commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Hello @lievendf, and thank you for this PR! I've had a look and it does indeed address a bug in the internal handling of drawing names.

Since this is a non-trivial fix, we'll need you to sign our CAA before we can proceed. Please see the Contributing.md file in the repo for details on the process..

The CAA form can be downloaded as a PDF here. The signed form should be emailed to github at epplussoftware dot com.

Once that's in place we'll do a full review and follow up with any feedback.

@lievendf lievendf force-pushed the fix/drawing-rename-removal-failure branch from 59d42c0 to 571d061 Compare June 16, 2026 13:47
@swmal swmal merged commit c6ef977 into EPPlusSoftware:develop8 Jun 18, 2026
3 checks passed
@lievendf lievendf deleted the fix/drawing-rename-removal-failure branch June 29, 2026 11:18
JanKallman added a commit that referenced this pull request Jun 30, 2026
* Feature/pivotbyv2 (#2365)

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* Fixed failing test

* New pivotby branch

* Added some failing unit tests

* WIP

* WIP

* WIP

* WIP

---------

Co-authored-by: swmal <897655+swmal@users.noreply.github.com>

* #2311 - Implemented new Excel functions (#2364)

* #2311 - Implemented WRAPROWS and WRAPCOLS

* #2311 - Implemented USDOLLAR

* #2311 - Implemented CODE and ENCODEURL functions

* #2311 - Added Array support for DOLLAR, USDOLLAR, CODEAND ENCODEUR

* #2311 - Added EPPlus version to FunctionMetadata

* EPPlus version 8.6.0

* Fix: ExcelWorksheets.Delete throws NotSupportedException on ExcelChartsheet (#2367)

The Delete method was attempting to access the PivotTables collection on all worksheet types. However, ExcelChartsheet throws NotSupportedException when accessing PivotTables. Added a type guard to skip PivotTable cleanup for chart sheets.

Co-authored-by: Lieven De Foor <lieven.de.foor@tvh.com>

* Fixes issue #2372

* Updated test

* Fixed test that affected static values of the Chart Style Manager, causing a later test to fail

* Fix case-sensitivity enum parsing bug in ExcelChartAxisStandard MajorTickMark and MinorTickMark (#2370)

Co-authored-by: Lieven De Foor <lieven.de.foor@tvh.com>

* Fixed some trendline issues

* Fixes issue #2376

* Removed, renamed and fixed a few issues

* Added new ActualPosition property for axis

* Re-implemented pie-chart and explosion

* Fixed trendline formulas to add superscript to textboxs

* Added debug properties to pie slices

* Deactivated debug props + cleanup

* Simplified constructor

* Fixed most trendline sub/superscript issues + rect

* Added margins to rect

* Half fix for duplication

* Fixed datalabel positions. Messily.

* Fixed datalabels more. Started fixing centering trendline

* Fixed DrawingTextBox duplicate properties

* Fixed Most of trendline centering

* Added spacing in trendline strings

* Fixed stacking axis

* Tweaked tests. Added recalculation to textbody

* Fixed positioning of stacked axis

* WIP:Axis positioning and sizeing

* Fixed line-ending issue

* Verified vertical alignment also functional

* Changed TextBox. GroupItem realtime. + margin grp

* Added tests for new textbox

* Fixed alignment bug and in ChartTitle.DisplayedText

* Partial trendline fix

* Partial fix for trendline autosize alignment issue

* Functional Trendlines fix

* #2383 - Fixed issue where VLOOKUP and HLOOKUP sometimes returned wrong value on unsorted data. (#2384)

* #2383 - Fixed issue where VLOOKUP and HLOOKUP sometimes returned wrong value on unsorted data

* #2483 - Fix approximate VLOOKUP/HLOOKUP to match Excel

* Fixed center-alignment for shapes

* Fixed sIcon location on datalabel

* Fixes axis position

* Fixed width of textbox

* Added fix for html images

* Feature/regexfunctions (#2373)

* WIP

* WIP

* WIP

* WIP

* WIP

* Fix REGEXEXTRACT/REGEXREPLACE scalar bugs: invalid return_mode validation, no-match now returns #N/A, empty pattern inserts replacement. Split regex tests into one file per function, verified against Excel desktop.

* Refactored unit tests

---------

Co-authored-by: swmal <897655+swmal@users.noreply.github.com>
Co-authored-by: swmal <{ID}+username}@users.noreply.github.com>

* Fixed multiple paragraph test

* Temporary fix for exact font

* Bugi2381 - ConditionalFormatting DxfStyleId miss-match  (#2386)

* Potential solution/verification ids off by 1

* Implemented better solution that does not break tests

* Cleanup

* Additional cleanup

* WIP:Added first test for errorbars

* Fixed infinite loop in GetTolColumnFromPixels.  (#2382)

* Fixed infinite loop in GetTolColumnFromPixels. Also fixed a crash when saving workbook with groupshape as a shape in a chart.

* Fixed positioning of shapes in charts

* get top and left no longer returns 0.

* fixed From To calculation for chart drawings.

* fixed absolute positioning

---------

Co-authored-by: Jan Källman <jan.kallman@epplussoftware.com>

* Fixed issue where rotated text would partially hide border (#2380)

* Fixed issue where rotated text would partially hide border

* Fixed several bugs in the HTML export. Row height was not set using invariant culture. Pattern fill was incorrect when the color was blank. Border style was not correct for Right and Bottom borders on merged cells

* Solved rotated column headers + savefile location

---------

Co-authored-by: Jan Källman <jan.kallman@epplussoftware.com>
Co-authored-by: Ossian Edström <ossian.edstrom@epplussoftware.com>

* Fixed some issues on chart axis and legends.

* Partial fix for datalabels

* EPPlus version 8.6.1

* Fixed background for datalabels

* Removed some warnings, mostly due to usage of ExpectedException in UnitTests

* Replaced DataTestMethod->TestMethod in unit tests

* Fixed small error in positioning of shapes in charts

* Transferred piechart legend special case

* Fixed label position on horizontal axis

* Fixes axis label alignment and label positioning

* Fixed centering of piechart legend

* Start of datalabels for barcharts

* Fixed out-end for bar-charts

* Functional datalabels

* Columnn and bar charts correct

* fixed stacked column pos datalabels

* Start of better datalabel system+debug

* Started Work on error bars

* New position functional for center and in-base

* Made labels work for inEnd and inBase again

* Added outEnd

* Simplified initilization in barChart

* Made new system functional for bars AND columns

* Fix KeyNotFoundException/ArgumentException on renaming or removing standard/grouped drawings (#2379)

Co-authored-by: Lieven De Foor <lieven.de.foor@tvh.com>

* Fix IndexOutOfRangeException in LoadFromText with trailing columns (#2388)

Co-authored-by: Lieven De Foor <lieven.de.foor@tvh.com>

* Fix url of license information in Readme.md (#2389)

* Ensured mix of series and custom datalabels get read

* Fix: drawing hyperlink reassignment crashes and inert tooltip setting (#2378)

Co-authored-by: Lieven De Foor <lieven.de.foor@tvh.com>

* Added support for negative columns + margin

* Ensured works for bar charts as well

* Added simpler but somewhat unclear method

* Attempting to use functionality in pie item

* Fixed several pie chart datalabel bugs

* Fixed bugs and cleaned up datalabels

* Cleanup and added all pie datalabels to same file

* Start of adding svg to html export

* Render of Errorbars for line charts

* Added html tests

* Fixed Errorbars issue

* Added category test

* Fixed gapwidth for barcharts

* Strong named EPPlus.DrawingRenderer and added tests for .NET 4.6.2.

* Added stylemanager styling

* Fixed ellipse items having rect type

* Fixed trendline label positioning

* Fixed trendline label positioning.

* Fixed databar bug + styling border issue

* Fixed null color for shapes and charts

* Fixed blip fills

* Start of fix for title element

* Fixed title bug in epplus

* Fixes errorbars for bar charts

* Fixed one test-failure

* Fixed Line Markers

* Fixed failing tests for Archivo Narrow

* Fixed corrupting issues with previous fix

* Turned off debug points for dlbl

* Fixed axis and trendlines issues

* Differing shape and chart fill

* Attempt att resolving style hierarchy correctly

* Added new option class to the ToSvg method

* Adding additional tests

* Fix for autofit columns with autofilters (#2390)

* Added base-functional chart export

* Allow AppVersion in OfficeProperties to be set to null. #2393. (#2394)

* Fixed absolute positioning for charts

* Start of relative position + multiple charts/shapes

* Documented change to DrawingFillBasic

---------

Co-authored-by: karlkallman <137038948+karlkallman@users.noreply.github.com>
Co-authored-by: swmal <897655+swmal@users.noreply.github.com>
Co-authored-by: Lieven De Foor <8639525+lievendf@users.noreply.github.com>
Co-authored-by: Lieven De Foor <lieven.de.foor@tvh.com>
Co-authored-by: OssianEPPlus <122265629+OssianEPPlus@users.noreply.github.com>
Co-authored-by: Ossian Edström <ossian.edstrom@epplussoftware.com>
Co-authored-by: swmal <{ID}+username}@users.noreply.github.com>
Co-authored-by: AdrianEPPlus <162118292+AdrianEPPlus@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants